/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller.user;

import java.util.List;
import queenb.net.entitybean.V200;
import queenb.web.controller.QueenbController;
import queenb.web.store.V200Store;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class V200Controller extends QueenbController{
    private int PV200;
    private String VV201;
    private String VV202;
    private V200Store v200Store;
    private boolean flag;
    
    public V200Controller()
    {
        v200Store = new V200Store();
        Object pv200Object = getRequest().getParameter("pv200");
        if(getRequest().getParameter("action") != null)
        {
            String action = getRequest().getParameter("action");
            if(action.equals("add"))
            {
                flag = true;
            }
            if(action.equals("edit"))
            {
                flag = false;
                this.PV200 = Util.parseInt(pv200Object);
                getListV200DetailEdit(PV200);
            }
        }
    }
    
    public List<V200> getListV200All()
    {
        try {
            List<V200> listV200 = v200Store.getListV200All(getLogin().getModule(),getLogin().getCompanyNo(), getLogin().getUserName());
            return listV200;
        } catch (Exception e) {
            return null;
        }
    }
    
    public void getListV200DetailEdit(int pv200i)
    {
        this.PV200 = pv200i;
        try{
            List<V200> listV200ByID = getListV200All();
            if(listV200ByID.size() > 0)
            {
                for(int i = 0; i < listV200ByID.size(); i++)
                {
                    if(listV200ByID.get(i).getPV200() == PV200)
                    {
                        this.VV201 = listV200ByID.get(i).getVV201();
                        this.VV202 = listV200ByID.get(i).getVV202();
                        break;
                    }
                }
            }
        }catch(Exception ex)
        {
              System.out.println("ERROR : " + ex.getMessage());
        }
    }
    
    public void updateV200()
    {
        if(flag == true)
        {
            int count = v200Store.updateV200(PV200,getLogin().getModule(),getLogin().getCompanyNo(), VV201, VV202, getLogin().getUserName());
             if (count > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        }else{
            int count = v200Store.updateV200(PV200,getLogin().getModule(),getLogin().getCompanyNo(), VV201, VV202, getLogin().getUserName());
             if (count > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        }
        sendRedirectUrlTab("setting.jsp?tab=header5&"+Util.convertMD5(getRequest().getRequestURI()));
    }

    /**
     * @return the PV200
     */
    public int getPV200() {
        return PV200;
    }

    /**
     * @param PV200 the PV200 to set
     */
    public void setPV200(int PV200) {
        this.PV200 = PV200;
    }

    /**
     * @return the VV201
     */
    public String getVV201() {
        return VV201;
    }

    /**
     * @param VV201 the VV201 to set
     */
    public void setVV201(String VV201) {
        this.VV201 = VV201;
    }

    /**
     * @return the VV202
     */
    public String getVV202() {
        return VV202;
    }

    /**
     * @param VV202 the VV202 to set
     */
    public void setVV202(String VV202) {
        this.VV202 = VV202;
    }

    /**
     * @return the flag
     */
    public boolean isFlag() {
        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
